package com.lcubigdata.controller;

import cn.hutool.core.io.IoUtil;
import com.lcubigdata.pojo.User;
import com.lcubigdata.service.UserService;
import com.lcubigdata.service.impl.UserServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户信息Controller
 */
@RestController // @ResponseBody -> 作用: 将controller返回值直接作为响应体的数据直接响应; 返回值是对象/集合->json->响应
public class UserController {


/*    public List<User> list() {
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("user.txt");
        ArrayList<String> lines= IoUtil.readLines(in, StandardCharsets.UTF_8,new ArrayList<>());

        List<User> userlist =lines.stream().map(line -> {
            String[] split = line.split(",");
            Integer id=Integer.parseInt(split[0]);
            String username=split[1];
            String password=split[2];
            String name=split[3];
            Integer age=Integer.parseInt(split[4]);
            LocalDateTime updateTime=LocalDateTime.parse(split[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new User(id,username,password,name,age,updateTime);
        }).toList();

        System.out.println(userlist);
        System.out.println("我没有数据");
        return userlist;
    }*/

    @Autowired
    private UserService userService;

    @RequestMapping("/list")
    public List<User> list() {

        List<User> userlist = userService.findAll();
        return userlist;
    }



}
